# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.firefox.webdriver import Options
from selenium.webdriver.common.by import By
from time import sleep
from lxml import etree
import os
import requests
'api接口https://temp.163.com/special/00804KVA/cm_guoji.js?callback=data_callback' \
'm_guoji.js国际可以变化 ，guonei'
def prase_page(html):
    tree=etree.HTML(html)
    div_list=tree.xpath('//div[@class="ndi_main"]/div')
    for div in div_list:
        href=div.xpath('.//div[@class="news_title"]/h3/a/@href')
        print(href)



def main():
    fox_option=Options()
    fox_option.add_argument('--headless')
    fox_option.add_argument('--disable-gpu')#如果是pc加上这个
    bro=webdriver.Firefox(executable_path='C:/py/Scripts/geckodriver.exe',firefox_options=fox_option)
    bro.implicitly_wait(10)#十秒隐士等待
    bro.get(url)
    sleep(1)
    #翻到页底
    bro.execute_script('window.scrollTo(0,document.body.scrollHeight)')
    sleep(0.5)
    #bro.find_element(By.CSS_SELECTOR, '.load_more_btn').click()
    bro.execute_script('window.scrollTo(0,document.body.scrollHeight)')
    sleep(0.5)
    sourse=bro.page_source
    prase_page(sourse)
    bro.quit()






if __name__=='__main__':
    url='https://news.163.com/world/'
    headers = {"User-Agent": 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0'}
    main()
